<template>
	<view  >
		<u-modal :show="show" :title="title" :content='content' @confirm="confirm"></u-modal>
		<vol-alert>
			<view>个人信息</view>
		</vol-alert>
		<view class="form-test">
	
		 
		<vol-form @input-confirm="inputConfirm" @extraClick="extraClick" @onChange="onChange" :load-key="true"
			ref="form" :form-options.sync="editFormOptions" :formFields.sync="editFormFields">
		</vol-form>	
		 
		

		<view class="btns">
			<!-- <view class="btn">
				<u-button type="primary" @click="reset" shape="circle" text="重置表单"></u-button>
			</view> -->
			<view class="btn">
				<u-button type="primary" @click="vailForm" shape="circle" text="递交信息"></u-button>
			</view>
		</view>
			</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				test: {
					a: 1,
					b: 2
				},
				show: false,
				title: '提示',
				content: '您的需要已递交系统审核，请耐心等候！',
				editFormFields: {
					studentName: "",
					studentPhone: "",
					studentArea: "",
					studentTeachingMethod: "",
					price: "",
					number: "",
					studentTime: "",
					studentAddress: "",
					studentDescribe: "",
					teacherRequirements: "",
                    remark1:""

				},
				editFormOptions: [{
						"title": "姓名",
						"required": true,
						"field": "studentName",
						"maxlength": "11",
					},
					{
						"title": "联系电话",
						"required": true,
						"field": "studentPhone",
						"maxlength": "11",
						"type":"number"

					},
					{
						"title": "学员性别",
						"required": true,
						"field": "studentGender",
						type: "select",
						data: [{
							"key": "男",
							"value": "男"
						}, {
							"key": "女",
							"value": "女"
						}],
					},
					{
						"title": "学员年级",
						"required": true,
						"field": "studentGrade",
						type: "select",
						data: [{
							"key": "一年级",
							"value": "一年级"
						}, {
							"key": "二年级",
							"value": "二年级"
						}],
					},
					{
						"title": "家教科目",
						"required": true,
						"field": "studentParentingSubjects",
						type: "selectList",
						data: [{
							"key": "语文",
							"value": "语文"
						}, {
							"key": "数学",
							"value": "数学"
						}, {
							"key": "英语",
							"value": "英语"
						}],
					},
					{
						"title": "家教区域",
						"required": true,
						"field": "studentArea",
						type: "select",
						data: [{
							"key": "昌平区",
							"value": "昌平区"
						}, {
							"key": "海淀区",
							"value": "海淀区"
						}],
					},
					{
						"title": "授课方式",
						"field": "studentTeachingMethod",
						type: "select",
						"required": true,
						data: [{
							"key": "线上",
							"value": "线上"
						}, {
							"key": "线下",
							"value": "线下"
						}],
						// key: "pn"
					},
					{
						"title": "家教费用",
						"field": "price",
						type: "select",
						"required": true,
						data: [{
								"key": "80/小时",
								"value": "80/小时"
							}, {
								"key": "90/小时",
								"value": "90/小时"
							},
							{
								"key": "100/小时",
								"value": "100/小时"
							}, {
								"key": "110/小时",
								"value": "110/小时"
							},
							{
								"key": "120/小时",
								"value": "120/小时"
							}, {
								"key": "面议",
								"value": "面议"
							}
						],
						// key: "pn"
					}, {
						"title": "参与数量",
						"field": "number",
						type: "select",
						"required": true,
						data: [{
								"key": "1",
								"value": "1"
							}, {
								"key": "2",
								"value": "2"
							},
							{
								"key": "3",
								"value": "3"
							}, {
								"key": "5",
								"value": "4"
							},
							{
								"key": "4",
								"value": "5"
							}, {
								"key": "6",
								"value": "6"
							}
						],
						// key: "pn"
					},
					{
						"title": "家教时间",
						"required": true,
						"field": "studentTime"
					},
					{
						"title": "家教地址",
						"required": true,
						"field": "studentAddress"
					},
					{
						"title": "学员描述",
						"field": "studentDescribe",
						type: "textarea4"
					}, {
						"title": "教员要求",
						"field": "teacherRequirements",
						type: "textarea5"
					},


				],
			}
		},
		methods: {
			confirm() {
				// uni.navigateBack();
				uni.navigateBack({
					delta: 1 // 返回的页面数，如果为1则表示返回上一级页面
				});
				// uni.switchTab({
				//     url: '/pages/home/home',
				    // params: {
				    //     name: '参数名',
				    //     value: '参数值'
				    // }
				// });
				 
			},
			extraClick(item) {
				//点击后给表字段设置值
				this.editFormFields.customInput = ~~(Math.random() * 10000000)
				this.$toast('表单按钮点击:' + item.title)
			},
			onChange(field, value, item, data) { //日期与下拉框选择事件
				if (field == "selectClickValue" || field == "dateClickValue") {
					this.$toast(`选择字段${field}值${value}`)
					return;
				}
				if (field == 'switchValue') {
					//获取单选字段配置
					let op = this.editFormOptions.find(c => {
						return c.field == 'radioVal'
					});
					//选择是时，隐藏【单选】字段
					this.$set(op, 'hidden', value + '' === "1")
					return;
				}
			},
			vailForm() {
				// if (!this.changePhone(this.studentPhone)) {
				// 	this.$toast("请输入正确的手机号码")
				// 	return;
				// }
				
				if (this.$refs.form.validate()) {
					// let UserInfo = this.$store.getters.getUserInfo();
					//   this.editFormFields.remark2=UserInfo.userId;
					  // console.log(this.editFormFields)


					 
					this.http.post("wechat/student/edit", this.editFormFields, "正在递交数据....").then(data => {
						if (data.code == 200) {
							// this.$toast(data.msg)
							this.show = true
							// 调用 uni.navigateBack() 函数关闭当前页面
							// uni.navigateBack({
							//     delta: 1 // 返回的页面数，如果为1则表示返回上一级页面
							// });
						} else {
							this.$toast(data.msg)
						}
					})

				}
			},
			reset() {
				this.$refs.form.reset();
				this.$toast("表单已重置")



			},
			changePhone(data) {
				let reg = /^1[3456789]\d{9}$/
				// 座机号校验
				let reg2 = /^0\d{2,3}-?\d{7,8}$/
				if (reg.test(data) || reg2.test(data)) {
					console.log("111")
					return true;
				} else {
					console.log("222")
					return false;
				}
			},

			inputConfirm(field, e) {
				this.$toast(`字段${field}回车事件`)
				console.log(field)
			},
			getNoticelist(e) {
				let that = this
				this.http.get("wechat/student/" + e, null, "正在查询数据....").then(data => {
			
					if (data.code == 200) {
						// this.$toast(data.msg)
						this.editFormFields = data.data;
			
					} else {
						this.$toast(data.msg)
					}
				})
			
			}
		},
		onShow() {

		},
		onReady() {
			//设置表单默认值请写在onReady中
			// this.editFormFields.inputText = 'vol框架';
		},
		onLoad(e) {
          console.log(e.id);
			if (e.id) {
            
			 this.getNoticelist(e.id);
			}
			
			
			
			
			// 
		}
	}
</script>

<style lang="less" scoped>
	.form-test {
		height: auto;
		margin-top: -20rpx;
		background: #f6f6f6;
		padding-top: 20rpx;
		margin-left: 20rpx;
		margin-right: 20rpx;
	}

	.btns {
		display: flex;
		padding: 0rpx 20rpx;
		margin-top: 40rpx;

		.btn {
			flex: 1;
			padding: 20rpx;
		}
	}
</style>
